﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SpaceFight
{
	public struct SliderSettings
	{
		public SliderSettings(object p_object, string p_property, float p_min, float p_max)
		{
			Object = p_object;
			Property = p_property;
			Maximum = p_max;
			Minimum = p_min;
		}
		public float Maximum;
		public float Minimum;
		public object Object;
		public string Property;
	}
	
	/// <summary>
	/// Interaction logic for UserControl1.xaml
	/// </summary>
	public partial class SettingSlider : UserControl
	{
		object m_object;
		string m_property;
		
		public SettingSlider(string p_name, SliderSettings p_settings)
		{
			InitializeComponent();
			
			nameLabel.Content = p_name;
			
			m_object = p_settings.Object;
			m_property = p_settings.Property;
			
			double initValue = (double)(float)m_object.GetType().GetProperty(m_property).GetValue(m_object, null);
			
			m_slider.Maximum = p_settings.Maximum;
			m_slider.Minimum = p_settings.Minimum;
			
			m_slider.Value = initValue;
		}

		private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
		{
			m_object.GetType().GetProperty(m_property).SetValue(m_object, (float)e.NewValue, null);
			valueLabel.Content = e.NewValue.ToString();
		}
	}
}
